//-----------------------------------------------------------------------------
//
// @file	Marching cubes.h
// @brief	Marching cubes algorithm from
//			http://paulbourke.net/geometry/polygonise/
// @date	13Aug2011
//
//-----------------------------------------------------------------------------

#ifndef _MARCHINGCUBES_H
#define _MARCHINGCUBES_H

#include "Vector.h"

//
//	http://paulbourke.net/geometry/polygonise/
//
//       Vertex index				Edge Index
//        
//		  4____________5		      _____4______
//        /|          /|		     /|          /|
//       / |         / |		    7 | 	    / |
//      /  |        /  |           /  8        5  9
//    7/___|______6/   |		  /___|_6_____/   |
//     |   |	   |   |		  |   |		  |   |
//     |  0/-------|---/1	      |   /----0--|---/
//     |  /		   |  /		     11  3		 10  /
//	   | /	       | /            | /         | 1
//     |/__________|/		      |/____2_____|/
//	   3         2			            
//

namespace MarchingCubes
{
	// Input : info about grid cell
	struct Input
	{
		float		isolevel;
		float		grid_values[8];		// For each grid vertices as ordered above
		Vector3		grid_pts[8];
	};

	// Output : triangles pointing to vertices
	struct Output
	{
		uint	num_vertices;
		uint	num_triangles;

		Vector3	vertices[12];
		uint	triangle_vtx_idices[15];
	};

	// Returns false if no triangles are formed
	bool Polygonize( const Input& param, Output& output );
};

#endif